import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_module/beans/data_layer_item_bean.dart';
import 'package:flutter_module/beans/data_layer_item_selection_bean.dart';
import 'package:flutter_module/viewModels/drawer_manager_viewmodel.dart';
import 'package:flutter_module/views/drawer_pages/base_page.dart';
import 'package:flutter_module/views/mapFragmentWidgets/map_title_bar.dart';
import 'package:provider/src/provider.dart';

class SingleSelectionPage extends BasePage {
  DrawerManagerViewModel? _read;

  @override
  MapTitleBarAdapter createMapTitleBarAdapter(BuildContext context) {
    _read ??= context.read<DrawerManagerViewModel>();
    return MapTitleBarAdapter(
      leading: BackButton(
        color: Colors.black,
        onPressed: () {
          _read!.backPage();
        },
      ),
      title: _read!.curDataLayer!.layerName,
    );
  }

  @override
  List<Widget> createWidgets(BuildContext context) {
    List<Widget> list = [];
    if (_read?.curItem?.selectOptions != null) {
      for (var it in _read!.curItem!.selectOptions!) {
        if (it is SelectionBean) {
          list.add(Card(
            child: ListTile(
              title: Text(it.name),
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                _read!.setCurItemValue(it.value);
              },
            ),
          ));
        }
      }
    }
    return list;
  }

  void dispose() {}

  @override
  void update() {}
}
